from django.db import models

# Create your models here.


class Device(models.Model):
    """
    设备表
    """
    name = models.CharField(verbose_name="名字", max_length=50)
    uuid = models.CharField(verbose_name="设备编号", max_length=256)
    type = models.ForeignKey('DeviceType', on_delete=models.CASCADE, null=True, blank=True)
    room = models.ForeignKey('roomManage.RoomMaster', on_delete=models.CASCADE)
    sort = models.IntegerField(verbose_name="排序", null=True, default=0)
    online = models.IntegerField(verbose_name="在线", null=True, default=0)   # 0.离线 1.在线
    status = models.IntegerField(verbose_name="状态", null=True, default=0)  # 0.正常 1.故障
    ip = models.CharField(verbose_name="IP", max_length=20, null=True, blank=True)
    icon = models.CharField(verbose_name="图标", max_length=128, null=True, blank=True)


class DeviceType(models.Model):
    """
    设备类型
    """
    name = models.CharField(verbose_name="名字", max_length=50)
    sort = models.IntegerField(verbose_name="排序", null=True, default=0)
    describe = models.CharField(verbose_name="描述", max_length=512, null=True, blank=True)


class Alarm(models.Model):
    """
    设备告警
    """
    createtime = models.DateTimeField(verbose_name="创建时间", auto_now_add=True, blank=True)
    # updatetime = models.DateTimeField(verbose_name="更新时间", auto_now=True, blank=True)
    device = models.ForeignKey('Device', on_delete=models.CASCADE, null=True, blank=True)
    reason = models.CharField(verbose_name="原因", max_length=512, null=True, blank=True)
    recovertime = models.DateTimeField(verbose_name="恢复时间", null=True, blank=True)
















